<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$system_name}管理中心 - {$page_name}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="__PUBLIC__/css/amazeui.min.css"/>
    <link rel="stylesheet" href="__PUBLIC__/css/admin.css"/>
    <link rel="stylesheet" href="__PUBLIC__/css/validform.css"/>
</head>
<body>
    <div class="admin-content">

        <!--页头-->
        <div class="am-cf am-padding">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">商品管理</strong> / <small>{$page_name}</small>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-2 am-u-sm-offset-8">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{:U('goods/goods_list')}" class="am-btn am-btn-default"><span class="am-icon-list"></span> 商品列表</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <hr/>
        <form method="post" class="am-form am-form-inline" id="goods_form">
        <input type="hidden" name="goods_id"/>
        <div class="am-tabs am-margin" data-am-tabs>
            <ul class="am-tabs-nav am-nav am-nav-tabs">
                <volist name="form_tab" id="list" key="key">
                <if condition="$key eq 1">
                <li class="am-active"><a href="#tab{$key}">{$list}</a></li>
                <else/>
                <li><a href="#tab{$key}">{$list}</a></li>
                </if>
                </volist>
            </ul>

            <!--表单项-->
            <div class="am-tabs-bd">
                <div class="am-tab-panel am-fade am-in am-active" id="tab1">
                    <volist name="base_info" id="list">
                        <switch name="list.type">
                            <case value="text">
                                <switch name="list.name">
                                    <case value="user_price">
                                        <div class="am-g am-margin-top-sm">
                                            <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                            <div class="am-u-sm-8 am-u-md-3 am-u-end am-form-inline">{:get_user_price_field($list['name'])}</div>
                                        </div>
                                    </case>
                                    <case value="discount_price">
                                        <div class="am-g am-margin-top-sm">
                                            <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                            <div class="am-u-sm-8 am-u-md-6 am-u-end">{:get_discount_price_field($goods_id)}</div>
                                        </div>
                                    </case>
                                    <case value="promotion_price">
                                        <div class="am-g am-margin-top-sm">
                                            <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                                <input type="checkbox" name="is_promoted" id="is_promoted" value="1"/> {$list.title}：
                                            </div>
                                            <div class="am-u-sm-8 am-u-md-3 am-u-end">
                                                <input type="{$list.type}" name="{$list.name}" id="{$list.name}" nullmsg="{$list.nullmsg}" disabled/>
                                            </div>
                                        </div>
                                    </case>
                                    <default/>
                                    <div class="am-g am-margin-top-sm">
                                        <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                        <div class="am-u-sm-8 am-u-md-3">
                                            <input type="{$list.type}" name="{$list.name}" id="{$list.name}" value="{:get_goods_info($goods_id,$list['name'])}" datatype="{$list.data_type}" nullmsg="{$list.nullmsg}" ignore="{$list.ignore}"/>
                                        </div>
                                        <div class="am-hide-sm-only am-u-md-6">
                                            <notempty name="list.is_must"><span class="am-text-danger am-text-xs">*必填</span></notempty>
                                            <switch name="list.name">
                                                <case value="goods_sn"><span class="am-link-muted am-text-xs">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span></case>
                                                <case value="give_integral"><span class="am-link-muted am-text-xs">购买该商品时赠送消费积分数</span></case>
                                                <case value="rank_integral"><span class="am-link-muted am-text-xs">购买该商品时赠送等级积分数</span></case>
                                                <case value="bought_integral"><span class="am-link-muted am-text-xs">(此处需填写金额)购买该商品时最多可以使用积分的金额</span></case>
                                            </switch>
                                        </div>
                                        </div>
                                </switch>
                            </case>
                            <case value="select">
                                <div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                    <div class="am-u-sm-8 am-u-md-3">
                                        <select name="{$list.name}" id="{$list.name}" datatype="{$list.data_type}"  nullmsg="{$list.nullmsg}" ignore="{$list.ignore}">
                                            <option value="">请选择...</option>
                                            <if condition="$list['name'] eq 'goods_category'">
                                                <volist name="goods_category" id="vo">
                                                    <option value="{$vo.category_id}">{$vo.category_name}</option>
                                                </volist>
                                            </if>
                                        </select>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-6">
                                        <switch name="list.name">
                                            <case value="goods_category">
                                                <button type="button" class="am-btn am-btn-secondary" style="margin-right:10px;" onclick="add_category();">添加分类</button>
                                            </case>
                                            <case value="goods_brand">
                                                <button type="button" class="am-btn am-btn-secondary" style="margin-right:10px;" onclick="add_brand();">添加品牌</button>
                                            </case>
                                        </switch>
                                        <notempty name="list.is_must"><span class="am-text-danger am-text-xs"> * 必填</span></notempty>
                                    </div>
                                </div>
                            </case>
                            <case value="hidden_select">
                                <div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                    <div style="display: none;">
                                        <select name="{$list.name}" id="{$list.name}">
                                            <option value="0">请选择...</option>
                                        </select>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-6">
                                        <button type="button" class="am-btn am-btn-secondary" onclick="add_extend_category(this);">添加</button>
                                        <button type="button" class="am-btn am-btn-secondary" style="display: none" onclick="cancle_extend_category(this);">取消</button>
                                    </div>
                                </div>
                            </case>
                            <case value="date">
                                <div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                    <div class="am-u-sm-8 am-u-md-9 am-form-inline">
                                        <div class="am-form-group am-form-icon">
                                            <i class="am-icon-calendar"></i>
                                            <input type="text" class="am-form-field" name="start_time" id="start_time" disabled>
                                        </div>
                                        <div class="am-form-group am-form-icon">
                                            <i class="am-icon-calendar"></i>
                                            <input type="text" class="am-form-field" name="end_time" id="end_time" disabled>
                                        </div>
                                    </div>
                                </div>
                            </case>
                            <case value="upload">
                                <div class="am-g am-margin-top-sm">
                                    <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                                    <div class="am-u-sm-8 am-u-md-3 am-u-end">
                                        <div class="am-form-group am-form-file">
                                            <button type="button" class="am-btn am-btn-secondary am-btn-sm">
                                                <i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
                                            <input id="goods_img" type="file" multiple>
                                        </div>
                                        <div id="file-list"></div>
                                    </div>
                                </div>
                            </case>
                        </switch>
                    </volist>
                </div>
                <div class="am-tab-panel am-fade" id="tab2">
                    <script id="container" name="content" type="text/plain"></script>
                </div>
                <div class="am-tab-panel am-fade" id="tab3"></div>
                <div class="am-tab-panel am-fade" id="tab4">
                    <volist name="other_info" id="list">
                        <div class="am-g am-margin-top-sm">
                            <div class="am-u-sm-4 am-u-md-3 am-text-right">{$list.title}：</div>
                            <switch name="list.type">
                                <case value="text">
                                    <div class="am-u-sm-8 am-u-md-3">
                                        <input type="{$list.type}" name="{$list.name}" id="{$list.name}"/>
                                    </div>
                                    <div class="am-hide-sm-only am-u-md-6"></div>
                                </case>
                                <case value="checkbox">
                                    <div class="am-u-sm-8 am-u-md-6 am-u-end">
                                        <div class="am-btn-group" data-am-button="">
                                        <if condition="$list.name eq 'goods_recommend_attr'">
                                            <volist name="recommend_attr" id="vo" key="key">
                                                <if condition="$key lt 4">
                                                    <label class="am-btn am-btn-default am-btn-xs"><input type="checkbox">{$vo}</label>
                                                </if>
                                            </volist>
                                        </if>
                                        </div>
                                    </div>
                                </case>
                                <case value="radio">
                                    <div class="am-u-sm-8 am-u-md-6 am-u-end">
                                        <div class="am-btn-group" data-am-button="">
                                        <if condition="$list.name eq 'is_on_sale'">
                                            <volist name="is_on_sale" id="vo" key="key">
                                                <label class="am-btn am-btn-default am-btn-xs"><input type="radio" name="is_on_sale">{$vo}</label>
                                            </volist>
                                        </if>
                                        <if condition="$list.name eq 'is_shipping_free'">
                                            <label class="am-btn am-btn-default am-btn-xs"><input type="radio" name="is_shipping_free">是</label>
                                            <label class="am-btn am-btn-default am-btn-xs"><input type="radio" name="is_shipping_free">否</label>
                                        </if>
                                        </div>
                                    </div>
                                </case>
                                <case value="textarea">
                                    <div class="am-u-sm-8 am-u-md-6 am-u-end">
                                        <textarea name="{$list.name}" id="{$list.id}" row="10"></textarea>
                                    </div>
                                </case>
                            </switch>
                        </div>
                    </volist>
                </div>
                <div class="am-tab-panel am-fade" id="tab5"></div>
            </div>

        </div>

        <div class="am-margin">
            <button type="button" class="am-btn am-btn-primary am-btn-xs" id="btn_sub">确定</button>
            <button type="button" class="am-btn am-btn-primary am-btn-xs">重置</button>
        </div>
        </form>
    </div>
</body>
<script type="text/javascript" src="__PUBLIC__/js/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/amazeui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/Validform/Validform_v5.3.2.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>
<script type="text/javascript">
var ROOT_PATH = '__ROOT__/admin.php';
$(function() {
    $('#goods_form').Validform({
        btnSubmit:"#btn_sub",
        tiptype:function(msg,o){
            if(o.type == 3){
                alert(msg);
                o.obj.addClass('am-field-error');
            }else{
                o.obj.removeClass('am-field-error');
            }
        },
        showAllError:true
    })

    //上传图片后显示文件名称
    $('#goods_img').on('change', function() {
        var fileNames = '';
        $.each(this.files, function() {
            fileNames += '<span class="am-badge">' + this.name + '</span> ';
        });
        $('#file-list').html(fileNames);
    });

    //选择促销后，促销价格，促销时间可填
    $('#is_promoted').click(function(){
        if($(this).is(':checked')){
            $('input:disabled').removeAttr('disabled');
            $('#promotion_price').attr('datatype','n');
            $('#start_time').attr('datatype','*');
            $('#end_time').attr('datatype','*');
        }else{
            $('#promotion_price').attr('disabled','disabled');
            $('#start_time').attr('disabled','disabled');
            $('#end_time').attr('disabled','disabled');
            $('#promotion_price').attr('ignore','ignore');
            $('#start_time').attr('ignore','ignore');
            $('#end_time').attr('ignore','ignore');
        }

    });

    //商品详细信息-编辑器
    var ue = UE.getEditor('container',{
        serverUrl:ROOT_PATH + '/admin/upload_file'
    });
});

function add_price_input(obj){
    var html ='<div>' +
            '<a href="javascript:;" onclick="add_price_input(this)">[+]</a>' +
            '<span class="am-text-xs">优惠数量</span>' +
            '<input type="text" name="discount_amount[]" class="discount_amount" style="display:inline-block;width:30%;margin:0 10px;">' +
            '<span class="am-text-xs">优惠价格</span>' +
            '<input type="text" name="discount_price[]" class="discount_price" style="display:inline-block;width:30%;margin-left:10px;">' +
            '</div>';
    var discount_amount = $(obj).parent().find('.discount_amount').val();
    var discount_price  = $(obj).parent().find('.discount_price').val();
    if(!discount_amount){
        alert('请输入优惠数量');
        return false;
    }
    if(!discount_price){
        alert('请输入优惠价格');
        return false;
    }
    $(obj).parent().append(html);
}

function add_category(){
    layer.open({
        type:2,
        title:'添加商品分类',
        area:['300px','200px'],
        content:'category_info?type=ajax'
    })
}

function add_brand(){
    layer.open({
        type:2,
        title:'添加商品品牌',
        area:['300px','200px'],
        content:'brand_info?type=ajax'
    })
}

function add_extend_category(obj){
    $(obj).parent().prev().addClass('am-u-sm-8 am-u-md-3');
    $(obj).parent().prev().show();
    $(obj).hide();
    $(obj).next().show();
}

function cancle_extend_category(obj){
    $(obj).parent().prev().removeClass('am-u-sm-8 am-u-md-3');
    $(obj).parent().prev().hide();
    $(obj).hide();
    $(obj).prev().show();
}
</script>
</html>